﻿#pragma once
#include <stdint.h>
#include "RankBaseManager.h"

class RankManager : public TSingleton<RankManager>
{
public:
	// 定义成员变量
#define RANK_REGISTER(RankType, MiscType, iRankMaxNum, RankXXXManager, stRankXXXMgr) RankXXXManager stRankXXXMgr;
#include "RankRegister.h"
#undef RANK_REGISTER

public:
	RankManager();
	~RankManager();

public:

	// 填充键值
	void fillRankKey(JceData::CacheMiscRankKey& stRankKey, uint32_t iObjId, int64_t iRankParam1, int64_t iRankParam2, int64_t iExtraParam1, const string& sExtdata = "");

	// 更新排行
	void updateRank(uint32_t iRankType, uint32_t iSubId, uint32_t iObjId, int64_t iRankParam1, int64_t iRankParam2, int64_t iExtraParam1, const string& sExtdata = "");

	// 更新全局排行
	void updateAreaRank(uint32_t iRankType, uint32_t iSubId, uint32_t iObjId, uint32_t iRankParam, const string& sExtData = "");

	void clearAreaRank(uint32_t iRankType, uint32_t iSubId);

	// 获取排行榜
	void getRankList(int32_t iRankType, uint32_t iSubId, uint32_t iStartIndex, uint32_t iRankNum, vector<RankData>& vRankDat);

	// 获取并列排行榜
	void getTiedRankList(int32_t iRankType, uint32_t iSubId, uint32_t iRankId, uint32_t iRankNum, vector<RankData>& vRankData);

	RankData getSelfRank(int32_t iRankType, uint32_t iSubId, uint32_t iObjId);
	RankData getTiedSelfRank(int32_t iRankType, uint32_t iSubId, uint32_t iObjId);

public:
	// 获取用户前200名平均等级
	uint32_t getUserAverageLevel();

public:
	// GM
	void clearAllRank();
	void clearRank(int32_t iRankType);
	void clearSubRank(int32_t iRankType, uint32_t iSubId);
	void delFromRank(int32_t iRankType, uint32_t iSubId, uint32_t iObjId);

	int32_t getAreaList(uint32_t iRankType, uint32_t iSubRankType, uint32_t iStartIndex, uint32_t iRankNum, uint32_t iCharid, uint32_t seqid);

	int32_t getAreaBatchList(const ProtoMsg::Msg_Rank_GetAreaSubBatchList_CS & msgRequest, uint32_t seqid, uint32_t charid);

private:
	map<uint32_t, RankBaseManager*>		_mRankMgr;
	uint32_t 							_iUseless;
	uint32_t 							_iAverageLevel;
	uint32_t 							_iAverageLevelRefreshTime;
};